package com.itheima.d2_reflect_test;

import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Field;

/*
    对象框架
    目标：保存任意对象的字段和其数据到文件中去
 */
public class ObjectFrame {
      public void test01(Object obj) throws IOException, IllegalAccessException {
          PrintWriter writer = new PrintWriter(new FileOutputStream("dataa.txt", true));
          Class aClass = obj.getClass();
          writer.println("============="+aClass.getSimpleName()+"=========");
          Field[] fields = aClass.getDeclaredFields();
          for (Field field : fields) {
              field.setAccessible(true);
              String name = field.getName();
              Object o = field.get(obj);
              writer.println(o+"=="+name);

          }
          writer.close();
      }
}
